﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using OreSystem.Entities;
using OreSystem.DAL;
namespace OreSystem.BLL
{
    public class ItemBLL
    {
        private ItemDAL itemDAL = new ItemDAL();
        public IList<Item> GetAll()
        {
            return itemDAL.GetList();
        }       

        public IList<Item> GetItemByType(int t)
        {
           return itemDAL.GetItemByType(t);
        }

        public void Save(Item item) {
            itemDAL.Save(item);
        }

        public IList<Item> GetItemsByKeys(int type, string keys, DateTime dateTime) {
            return itemDAL.GetItemsByKeys(type, keys, dateTime).ToList().FindAll(i => i.CreateDate.ToShortDateString() == dateTime.ToShortDateString());
        }

        public Item GetItemById(int id) {
            return itemDAL.GetItemById(id);
        }

        public void Delete(Item item) {
            itemDAL.Delete(item);
        }

        public IList<Item> getItemsByDate(DateTime dt) {
            return ((List<Item>)GetItemsByKeys(1,"",dt)).FindAll(p=>p.CreateDate.ToShortDateString() == dt.ToShortDateString());
        }

        public IList<Item> GetListByPage(int type, int p, int rows,out int totals)
        {
            var lists = itemDAL.GetItemByType(type);
            totals = lists.Count;
            return lists.Skip(p * rows).Take(rows).ToList();
        }

        public void Deletes(IList<object> idList)
        {
            itemDAL.Deletes(idList);
        }

        public Item GetItemByCarId(int cid,DateTime date,int type)
        {
            return itemDAL.GetItemByCarId(cid, type).ToList().Find(i => i.CreateDate.ToShortDateString() == date.ToShortDateString());
        }
    }
}
